package cn.gjculture.shopping.api.service.impl;

import cn.gjculture.shopping.api.dao.ArtistVoteDao;
import cn.gjculture.shopping.api.entity.ArtistVote;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.ArtistVoteService;
import cn.gjculture.shopping.api.util.DateUtil;
import cn.gjculture.shopping.api.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArtistVoteServiceImpl implements ArtistVoteService {

    @Autowired
    ArtistVoteDao artistVoteDao;

    @Override
    public int insert(ArtistVote artistVote, Return ret) {
        ArtistVote vote=artistVoteDao.queryByCustomerId(artistVote.getCustomerId());
        if(vote!=null){
            ret.getCommon().setMessage("你已经投过票了");
            ret.getCommon().setRet(false);
            return 0;
        }
        artistVote.setArtistId(UUIDUtil.getUUID());
        artistVote.setVoteTime(DateUtil.getTimestamp());
        artistVoteDao.insert(artistVote);
        return 1;
    }

    @Override
    public List<ArtistVote> query() {
        return artistVoteDao.query();
    }

}
